<?php
namespace Admin\Model;
use Think\Model;
class CatModel extends Model{
    public $cats;
    public function __construct(){
        parent::__construct();
        $this->cats = $this->select();
    }
    public function getTree($id=0,$lev=0){
        $tree = [];
        foreach ($this->cats as $k => $v) {
            if($v['parent_id'] == $id){
                $v['lev'] = $lev;
                $tree[] = $v;
                $tree = array_merge($tree,$this->getTree($v['cat_id'],$lev+1));
            }
        }
        return $tree;
    }


    public function mbx($cat_id){
        $row = $this->find($cat_id);
        $tr[] = $row;
        while ($row['parent_id'] > 0) {
            $row = $this->where('cat_id='.$row['parent_id'])->find();
            $tr[] = $row;
        }

        return array_reverse($tr);
    }

}
